package com.test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;


//ExecutorService、Callable<Class>、Future 有返回值线程
public class demo1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(10);
        List<Future> list = new ArrayList<>();
        for(int i=0;i<10;i++){
            Callable c = new MyCallable(i + " ");
            Future future = pool.submit(c);
            list.add(future);
        }

        pool.shutdown();

        for(Future f : list){
            System.out.println("res: "+f.get().toString());
        }
    }

    static class MyCallable implements Callable{
        public String res;
        @Override
        public Object call() throws Exception {
            return res;
        }

        MyCallable(String i){
            res = i;
        }
    }
}
